package com.rd.student.jiaji.class1.jinhongyu.day0808;

import java.io.*;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) throws IOException {

        File file = new File("Student.txt");
        file.createNewFile();

        Student s1 = new Student();
        Student s2 = new Student();
        Student s3 = new Student();

        shuru3(s1);
        shuru3(s2);
        shuru3(s3);//从键盘输入创建三学生

        InputStream is = new FileInputStream(file);
        OutputStream os = new FileOutputStream(file);
        String str = "姓名 语文成绩 数学成绩 总分\n";
        byte[] arr = str.getBytes();
        os.write(arr);

        StringBuffer stringBuffer1 = new StringBuffer();
        stringBuffer1.append(s1.getName()+" ");
        stringBuffer1.append(s1.getYuwen()+" ");
        stringBuffer1.append(s1.getShuxue()+" ");
        stringBuffer1.append(s1.totall()+"\n");

        StringBuffer stringBuffer2 = new StringBuffer();
        stringBuffer2.append(s2.getName()+" ");
        stringBuffer2.append(s2.getYuwen()+" ");
        stringBuffer2.append(s2.getShuxue()+" ");
        stringBuffer2.append(s2.totall()+"\n");

        StringBuffer stringBuffer3 = new StringBuffer();
        stringBuffer3.append(s3.getName()+" ");
        stringBuffer3.append(s3.getYuwen()+" ");
        stringBuffer3.append(s3.getShuxue()+" ");
        stringBuffer3.append(s3.totall()+"\n");

        String s11 = String.valueOf(stringBuffer1);
        String s12 = String.valueOf(stringBuffer2);
        String s13 = String.valueOf(stringBuffer3);

        byte[] arr1 = s11.getBytes();
        byte[] arr2 = s12.getBytes();
        byte[] arr3 = s13.getBytes();

        os.write(arr1);
        os.write(arr2);
        os.write(arr3);

        is.close();
        os.close();

    }
    public static void shuru3(Student student){

        System.out.println("请输入学生姓名:");
        Scanner scanner1 = new Scanner(System.in);
        String s = scanner1.nextLine();

        System.out.println("请输入学生语文成绩(0-100)");
        Scanner scanner2 = new Scanner(System.in);
        int a = Integer.parseInt(scanner2.nextLine());

        System.out.println("请输入学生数学成绩(0-100)");
        Scanner scanner3 = new Scanner(System.in);
        int b = Integer.parseInt(scanner3.nextLine());

        student.setName(s);
        student.setYuwen(a);
        student.setShuxue(b);

        System.out.println("录入成功");
    }
}

